package com.company.woye.dbhmanagerdetail.activity;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.company.woye.R;
import com.company.woye.base.BaseActivity;
import com.company.woye.boxmanagerdetail.adapter.InefficiencyNumberListViewAdapter;
import com.company.woye.dbhmanagerdetail.adapter.SingleNumberListviewAdapter;

import butterknife.BindView;
import butterknife.OnClick;

public class DbhDetailActivity extends BaseActivity {

    @BindView(R.id.lv_single_number_summary)
    ListView summaryListView;

    @BindView(R.id.ll_single_number_summary)
    LinearLayout summaryLinearLayout;

    @BindView(R.id.tv_single_number_summary)
    TextView summaryTextView;

    @BindView(R.id.lv_single_number_detail)
    ListView detailListView;

    @BindView(R.id.ll_single_number_detail)
    LinearLayout detailLinearLayout;

    @BindView(R.id.tv_single_number_detail)
    TextView detailTextView;

    @BindView(R.id.lv_single_number_number)
    ListView numberListView;

    @BindView(R.id.ll_single_number_number)
    LinearLayout numberLinearLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int setLayoutId() {
        return R.layout.activity_dbh_detail;
    }

    @Override
    public void initView() {
        summaryListView.setAdapter(new SingleNumberListviewAdapter(this));
        detailListView.setOnItemClickListener((parent, view, position, id) -> {
            numberLinearLayout.setVisibility(View.VISIBLE);
            numberListView.setVisibility(View.VISIBLE);
            numberListView.setAdapter(new InefficiencyNumberListViewAdapter(this));
        });
    }
    @OnClick({R.id.iv_single_number_back,R.id.tv_single_number_summary, R.id.tv_single_number_detail,R.id.tv_single_number_out_goods})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.iv_single_number_back:
                finish();
                break;
            case R.id.tv_single_number_summary:
                summaryTextViewOnClick();
                break;
            case R.id.tv_single_number_detail:
                detailTextViewOnClick();
                break;
            case R.id.tv_single_number_out_goods:
                dealNotesTextViewOnClick();
                break;
        }
    }

    private void summaryTextViewOnClick(){
        summaryLinearLayout.setVisibility(View.VISIBLE);
        detailLinearLayout.setVisibility(View.GONE);
        numberLinearLayout.setVisibility(View.GONE);
        numberListView.setVisibility(View.GONE);
        summaryListView.setAdapter(new SingleNumberListviewAdapter(this));
        summaryTextView.setTextColor(getResources().getColor(R.color.blue));
        detailTextView.setTextColor(getResources().getColor(R.color.darkGray));
    }


    private void detailTextViewOnClick(){
        summaryLinearLayout.setVisibility(View.GONE);
        detailListView.setAdapter(new InefficiencyNumberListViewAdapter(this));
        detailLinearLayout.setVisibility(View.VISIBLE);
        summaryTextView.setTextColor(getResources().getColor(R.color.darkGray));
        detailTextView.setTextColor(getResources().getColor(R.color.blue));
    }


    private void dealNotesTextViewOnClick() {
        View view = LayoutInflater.from(this).inflate(R.layout.popupwindow_out_bound, null);
        final PopupWindow popupWindow = new PopupWindow(view,  ViewGroup.LayoutParams.MATCH_PARENT/3, ViewGroup.LayoutParams.WRAP_CONTENT);
        ImageView back = view.findViewById(R.id.iv_out_bound_back);
        TextView top = view.findViewById(R.id.tv_pop_top_left);
        TextView hint1 = view.findViewById(R.id.tv_pop_hint1);
        TextView hint2 = view.findViewById(R.id.tv_pop_hint2);
        TextView hint3 = view.findViewById(R.id.tv_pop_hint3);
        TextView pause = view.findViewById(R.id.tv_pop_pause);
        TextView resume = view.findViewById(R.id.tv_pop_resume);
        EditText editText=view.findViewById(R.id.et_pop);
        editText.setVisibility(View.VISIBLE);
        back.setOnClickListener(v -> {
            popupWindow.dismiss();
        });
        top.setText("处理备注");
        hint1.setVisibility(View.GONE);
        hint2.setVisibility(View.GONE);
        hint3.setVisibility(View.GONE);
        hint1.setText("");
        hint2.setText("");
        pause.setBackgroundResource(R.drawable.stroke_blue);
        pause.setTextColor(getResources().getColor(R.color.blue));
        resume.setBackgroundResource(R.drawable.button_primary_shape);
        hint3.setText("");
        pause.setText("取消");
        resume.setText("确定");
        resume.setOnClickListener(v -> {
            popupWindow.dismiss();
        });
        pause.setOnClickListener(v -> {
            popupWindow.dismiss();
        });
        popupWindow.setFocusable(true);
        popupWindow.setTouchable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable());
        popupWindow.setOutsideTouchable(true);
        popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
    }
}
